<script lang="ts">
import { watchOnce } from '@peng_kai/kit/libs/vueuse';
import { globalPopups } from '~comp-b/global-popups';
import { ShareManager } from '~comp-b/share';
import { legacyLogicalPropertiesTransformer, Spin } from 'ant-design-vue';
import cs from '~/composables/useCS';
import { useLocale } from '~/modules/locale';
import { useAntdTheme } from '~/modules/theme';
import { holders } from '../antd-assist/holders';

import ActionManager from './ActionManager.vue';
import { useAdjustInit } from './useAdjustInit';
import { useProvideAppContext } from './useProvideAppContext';
import './helpers/index';
</script>

<script setup lang="ts">
const appStore = useAppStore();

useProvideAppContext({
  cdn: () => appStore.handshake?.domain.cdn,
  www: () => '',
});
const themeConfig = useAntdTheme();

Spin.setDefaultIndicator({
  indicator: h('i', { class: 'i-svg-spinners:ring-resize  text-brand' }),
});

const { userInfo } = storeToRefs(useUserStore());

watch(userInfo, cs.setup, { immediate: true });
useLocale();
useAdjustInit();
</script>

<template>
  <AConfigProvider hashPriority="high" :theme="themeConfig" :locale="JSON.parse(decodeURIComponent($t('antd')))">
    <AStyleProvider hashPriority="high" :transformers="[legacyLogicalPropertiesTransformer]">
      <component :is="Holder" v-for="Holder of holders" :key="Holder.name" />
      <component :is="Popup.PresetComponent" v-for="(Popup, name) of globalPopups" :key="name" />
      <ShareManager />
      <ActionManager />

      <slot />
    </AStyleProvider>
  </AConfigProvider>
</template>
